package com.v9.system.controller;


import com.v9.common.dto.IdDto;
import com.v9.common.web.AbstractController;
import com.v9.system.domain.Position;
import com.v9.system.service.PositionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@Tag(name = "岗位")
@Slf4j
@RequestMapping(value = "/system/post", method = RequestMethod.POST)
public class PositionController extends AbstractController {

    @Resource
    private PositionService positionService;

    @RequestMapping("/save")
    @Operation(summary = "添加/修改")
    public void save(@Valid @RequestBody PositionDto dto){
        positionService.saveOrInsert(clone(Position.class,dto));
    }

    @RequestMapping("/list")
    @Operation(summary = "查询所有的岗位")
    public List<PositionDto> list(){
        return clone(PositionDto.class,positionService.query(new Position()));
    }
    @RequestMapping("/view")
    @Operation(summary = "查询所有的岗位")
    public PositionDto view( @RequestBody IdDto dto){
        return clone(PositionDto.class,positionService.findById(dto.getId()));
    }


    @RequestMapping("/delete")
    @Operation(summary = "删除")
    public void delete(@Valid @RequestBody IdDto dto){
        positionService.remove(dto.getId());
    }

    @Data
    public static class PositionDto{
        @Schema(description = "岗位id")
        private Long id;
        @Schema(description = "名称")
        private String name;
        @Schema(description = "编码")
        private String code;
        @Schema(description = "排序")
        private Integer seq;
        @Schema(description = "状态")
        private Boolean status;
    }
}
